package com.deram.ctin.rest.web.controller.common;

import com.deram.ctin.common.bean.UploadResult;
import com.deram.ctin.common.utils.MultipartUtils;
import com.deram.ctin.serv.third.api.QiniuUploadApi;
import com.deram.ctin.serv.third.utils.QiniuUploadUtils;
import com.deram.ctin.serv.third.result.QiniuUpdateConfig;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@Api(tags = {"common - 上传接口"})
@RestController
@RequestMapping("/common/upload")
public class CommonUploadController {

    @Autowired
    private QiniuUploadApi qiniuUploadApi;

    @ApiOperation(value = "上传图片")
    @PostMapping("/image")
    public UploadResult uploadImage(MultipartFile uploadFile) {
        QiniuUpdateConfig config = qiniuUploadApi.getConfig();
        MultipartUtils.checkImage(uploadFile, config.getUploadMaxSize());
        return QiniuUploadUtils.upload(config, null, uploadFile);
    }
}
